import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Test
{

	public static void main(String[] args) throws IOException
	{
		System.out.println("请输入第一个数：");
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext())
		{
			System.out.println("请输入第二个数：");
			String num1 = sc.next();
			String num2 = sc.next();
			boolean is_minus_1 = false;
			boolean is_minus_2 = false;
			if (num1.contains("-"))
				is_minus_1 = true;
			if (num2.contains("-"))
				is_minus_2 = true;
			if (is_minus_1 && !is_minus_2)
			{
				calculateBigData(num1, num2, '-', 1);
			}
			else if (!is_minus_1 && is_minus_2)
			{
				calculateBigData(num2, num1, '-', 1);
			}
			else if (is_minus_1 && is_minus_2)
			{
				calculateBigData(num1, num2, '+', 2);
			}
			else
			{
				calculateBigData(num1, num2, '+', 3);
			}
		}
	}

	public static void calculateBigData(String num1, String num2, char c, int kind)
	{
		String s1a[] = num1.split(",");
		String s2a[] = num2.split(",");
		List<Integer> list1 = new ArrayList<Integer>();
		List<Integer> list2 = new ArrayList<Integer>();
		List<Integer> list_temp = new ArrayList<Integer>();
		List<Integer> list3 = new ArrayList<Integer>();
		boolean flag = false;
		switch (kind)
		{
			case 1:
				s1a[0] = String.valueOf(0 - Integer.parseInt(s1a[0]));
				break;
			case 2:
				s1a[0] = String.valueOf(0 - Integer.parseInt(s1a[0]));
				s2a[0] = String.valueOf(0 - Integer.parseInt(s2a[0]));
				break;
			case 3:
				break;
		}
		int k = 0;
		boolean pout = false;
		for (int i = 0; i < s1a.length; ++i)
		{
			int n = Integer.parseInt(s1a[i]);
			if (n > 0 || pout)
			{
				pout = true;
				list_temp.add((n + k) % 10000);
			}
			k = n / 10000;
		}
		for (int i = list_temp.size() - 1; i >= 0; --i)
		{
			list1.add(list_temp.get(i));
		}
		k = 0;
		pout = false;
		list_temp.clear();
		for (int i = 0; i < s2a.length; ++i)
		{
			int n = Integer.parseInt(s2a[i]);
			if (n > 0 || pout)
			{
				list_temp.add((n + k) % 10000);
				pout = true;
			}
			k = n / 10000;
		}
		for (int i = list_temp.size() - 1; i >= 0; --i)
		{
			list2.add(list_temp.get(i));
		}
		Iterator<Integer> it1 , it2;
		if (list1.size() == 0)
		{
			list1.add(0);
		}
		if (list2.size() == 0)
		{
			list2.add(0);
		}
		int n = 0;
		switch (c)
		{
			case '-':
				if (list1.size() < list2.size())
				{
					list_temp = list1;
					list1 = list2;
					list2 = list_temp;
					flag = true;
				}
				else if (list1.size() == list2.size())
				{
					for (int i = list1.size() - 1; i >= 0; --i)
					{
						if (list1.get(i) > list2.get(i))
						{
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						list_temp = list1;
						list1 = list2;
						list2 = list_temp;
						flag = true;
					}
					else
					{
						flag = false;
					}
				}
				n = 0;
				int j = 0;
				int m = 0;
				it1 = list1.iterator();
				it2 = list2.iterator();
				while (it1.hasNext() || it2.hasNext())
				{
					if (it1.hasNext())
					{
						n = it1.next() + m;
						j++;
					}
					if (it2.hasNext())
					{
						int temp = it2.next();
						if (n >= temp)
						{
							n -= temp;
							m = 0;
						}
						else
						{
							n = n + 10000 - temp;
							m = -1;
						}
					}
					if (n < 0)
					{
						n += 10000;
						m = -1;
					}
					if (n != 0 || j != list1.size())
						list3.add(n);
				}
				break;
			case '+':
				n = 0;
				it1 = list1.iterator();
				it2 = list2.iterator();
				while (it1.hasNext() || it2.hasNext())
				{
					if (it1.hasNext())
					{
						n += it1.next();
					}
					if (it2.hasNext())
					{
						n += it2.next();
					}
					list3.add(n % 10000);
					n /= 10000;
				}
				if (n != 0)
				{
					list3.add(n);
				}
				break;
			default:
				break;
		}
		int p = 0;
		if (list3.size() == 0)
		{
			list3.add(0);
		}
		for (int i = list3.size() - 1; i >= 0; --i)
			if (list3.get(i) != 0)
			{
				p = i;
				break;
			}
		n = list3.get(p);
		switch (kind)
		{
			case 1:
				if (!flag)
				{
					System.out.printf("%d", -n);
				}
				else
				{
					System.out.printf("%d", n);
				}
				break;
			case 2:
				System.out.print("-");
				System.out.printf("%d", list3.get(p));
				break;
			case 3:
				System.out.printf("%d", list3.get(p));
				break;
		}
		for (int i = p - 1; i >= 0; --i)
		{
			System.out.printf(",%04d", list3.get(i));
		}
		System.out.println("请输入第一个数： ");
	}
}
